FROM centos:7
MAINTAINER gaork "testsroot@163.com>"

# -----------------------------------------------------------------------------
# 安装工具
# -----------------------------------------------------------------------------
# epel源安装
RUN yum install -y epel-release \
# 安装REMI仓库
    && yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm \
# 配置yum 开启remi-php71
    && yum-config-manager --enable remi-php71

# -----------------------------------------------------------------------------
# 安装php及扩展
# 如是php自带扩展则使用如 php-mcrypt
# 如是pecl上的扩展则使用如 php-pecl-redis
# -----------------------------------------------------------------------------
ENV PHP_VERSION=7.1
RUN yum -y install php71 \
    php71-php-fpm \
    php71-php-xml \
    php71-php-xml \
    php71-php-mcrypt \
    php71-php-mbstring \
    php71-php-mysql \
    php71-php-gd \
    php71-php-soap \
    php71-php-opcache \
    php71-php-bcmath \
    php71-php-pecl-zip \
    php71-php-pecl-redis \
    php71-php-pecl-amqp \
    php71-php-pecl-mosquitto \
    && ln -s /opt/remi/php71/root/usr/bin/{phar,php,php-cgi,phpize} /usr/local/bin \
    && ln -s /opt/remi/php71/root/usr/sbin/php-fpm /usr/sbin \
    && yum -y install python-setuptools -y && easy_install supervisor

# 配置supervisor
RUN mkdir -p /etc/supervisord.d
COPY conf/supervisord.conf /etc/supervisord.conf

# PHP配置文件更改
COPY conf/php.ini /etc/opt/remi/php71/php.ini
COPY conf/php-fpm.conf /etc/opt/remi/php71/php-fpm.conf
COPY conf/www.conf /etc/opt/remi/php71/php-fpm.d/www.conf

#创建www-data用户
RUN useradd www-data -s /sbin/nologin

#更新www-data操作目录权限
RUN chown -R www-data. /var/opt/remi/php71/lib/php

# 容器启动文件
COPY scripts/start.sh /start.sh
RUN chmod 755 /start.sh

# -----------------------------------------------------------------------------
# 时区设置
# -----------------------------------------------------------------------------
ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# -----------------------------------------------------------------------------
# clean tmp file
# -----------------------------------------------------------------------------
RUN rm -rf /tmp/* \
    && yum clean all \
    && rm -rf /var/cache/yum

WORKDIR /var/www

EXPOSE 9000

CMD ["/start.sh"]
